
const path = require('path')
const webpack = require('webpack');
const HtmlwebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const CopyWebpackPlugin = require('copy-webpack-plugin');
const Base = require("./webpack.base");

/**
 * 打包源码
 */
module.exports = {
  mode: 'production',//'development',
  // 入口
  entry:"./index.js",
  // 出口
  output: {
      filename: 'build.js',
      publicPath: "./",
      path: Base.outPath,
  },
  optimization: {
    // 压缩混淆
    minimize: true,
  },
  performance: {
    hints:'warning',
    //入口起点的最大体积
    maxEntrypointSize: 50000000,
    //生成文件的最大体积
    maxAssetSize: 30000000,
    //只给出 js 文件的性能提示
    assetFilter: function(assetFilename) {
      return assetFilename.endsWith('.js');
    }
  },
  module: {
    rules: [
    ]
  },
  resolve: {
    // 设置别名
    alias: {
      '@': Base.inputRootPath
    }
  },
  plugins: [
    new CleanWebpackPlugin({
      cleanOnceBeforeBuildPatterns: ["dist"]
    }),
    new CopyWebpackPlugin({
      patterns:  [
        { 
          from: 'dll/*.js', 
          to: Base.outPath,
          flatten: true
         },
      ],
      options: {
        // 并发
        concurrency: 100,
      },
    }),
    new webpack.DefinePlugin({
      'process.env': {
          'NODE_ENV': JSON.stringify('production')
      }
    }),
    new HtmlwebpackPlugin({
      title: 'Webpack-demos',
      filename: 'index.html',
      template: './index.html',
      inject: true,
    }),
    new webpack.DllReferencePlugin({
      manifest: require('./manifest/axios.manifest.json')
    }),
    new webpack.DllReferencePlugin({
      manifest: require('./manifest/threejs.manifest.json')
    }),
    new webpack.ids.HashedModuleIdsPlugin({
      hashFunction: 'sha256',
      hashDigest: 'hex',
      hashDigestLength: 20
    }),
  ],
  externals: {
  }
}